<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>上传图片并保存到后端</title>
</head>
<body>
<input type="file" id="fileInput">
<button onclick="uploadImage()">上传并保存到后端</button>

<script>
    function uploadImage() {
        const fileInput = document.getElementById('fileInput');
        const file = fileInput.files[0];
        const formData = new FormData();

        formData.append('image', file);

        fetch('/image/upload', {
            method: 'POST',
            body: formData
        })
        .then(response => response.text())
        .then(result => {
            console.log(result); // 处理后端返回的结果
        })
        .catch(error => {
            console.error('发生错误:', error);
        });
    }
</script>
</body>
</html>
